/*
 *
 *  * Copyright (c) 2016. For Intelligent Group.
 *
 */

package com.intelligent.mts.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

/**
 * Created by yangli on 2016-07-26.
 */
public class PropertyManager {
    public static Logger logger = LoggerFactory.getLogger(PropertyManager.class);

    private String CONFIG_FILE = "";

    private Properties configProps = new Properties();


    public PropertyManager(String file) {
        CONFIG_FILE = file;
        configProps = new Properties();

        try {
            logger.info(Thread.currentThread().getContextClassLoader().getResource(CONFIG_FILE).getPath());

            configProps.load(new FileInputStream(Thread.currentThread().getContextClassLoader().getResource(CONFIG_FILE).getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getProperty(String key) {
        String propertyValue = (String) configProps.getProperty(key);
        return propertyValue;
    }

    public int getPropertyAsInt(String key) {
        int intValue = 0;
        try {
            intValue = Integer.parseInt(getProperty(key));
        } catch (NumberFormatException e) {
            intValue = 0;

        }
        return intValue;
    }

    public Properties getProperties() {
        return configProps;
    }

}
